
class wxpay{
	constructor(arg) {
		console.log(arg,"arg")
	    this.config=arg;
		this.packages=arg.package
	}

	pay(){
		 return new Promise((resolve, reject) => {
			uni.requestPayment({
				provider: 'wxpay',
				timeStamp:this.config.timeStamp,
				nonceStr:this.config.nonceStr,
				package:this.packages,
				signType:this.config.signType,
				paySign:this.config.paySign,
				success: function (res) {
					console.log(res)
				   resolve(res);
				},
				fail: function (err) {
					// uni.redirectTo({
					// 	url:"../../pages/book/index"
					// })
						reject(err);
				},
					complete: res => {
						console.error(res)
					}
			});
		})
	}
	
	h5pay(){
		return new Promise((resolve, reject) => {
			console.log(this.config,"this.config")
			WeixinJSBridge.invoke('getBrandWCPayRequest', {
			    "appId": this.config.appId, //公众号名称，由商户传入
			    "timeStamp": this.config.timeStamp, //时间戳
			    "nonceStr": this.config.nonceStr, //随机串
			    "package": this.packages, //扩展包
			    "signType": "MD5", //微信签名方式:MD5
			    "paySign":  this.config.paySign //微信签名
			}, function(res){
				console.log(res,"res")
				if (res.err_msg === "get_brand_wcpay_request:ok") {
				    resolve(res);
				} else if (res.err_msg === "get_brand_wcpay_request:cancel") {
				    console.log('用户取消支付')
				} else if (res.err_msg === "get_brand_wcpay_request:fail") {
				    console.log('支付失败')
				}
				
			}) 
		})
	
	}
}


 export default wxpay